use strict;
use File::Find;

my $level;
my $string;
my $inputs;

my $dir = "/var/www/perl/galleri/image_repository/";

find
(
 {
  postprocess => sub { $level--; },
  
  preprocess => sub {
    
    my @d = grep { !/^\.+$/ } sort { $a<=>$b } grep {-d $dir . $_} @_;
    
    (my $d=$_) =~ s|.*image_repository/?||;
    
    s|.*/image_repository||;
    s|/$||;
    s|.*/||;
    my  $ins = $level > 1 ? "aux".($level-1) : "foldersTree" ;
    $string .= sprintf qq{aux%d = insFld(%s, gFld("%s", "javascript:jsShowImages([\\"%s\\"],[\\"thumbs_here\\",\\"navpanel\\"])"))\n}, $level, $ins, $_, $d if $_;
    $level++;
    
    sort @_;
  },
  
  wanted => sub { return unless -d $_; (my $d=$_) =~ s|.*image_repository/?||; $inputs .= qq{<input id="$d" type="hidden" value="$d">} },
  
  no_chdir => 1,
  
 },
 
 "/var/www/perl/Gallery/image_repository",
 
);

## print "Content-type: application/x-javascript\n\n";

printf q{
//
// Copyright (c) 2006 by Conor O'Mahony.
// For enquiries, please email GubuSoft@GubuSoft.com.
// Please keep all copyright notices below.
// Original author of TreeView script is Marcelino Martins.
//
// This document includes the TreeView script.
// The TreeView script can be found at http://www.TreeView.net.
// The script is Copyright (c) 2006 by Conor O'Mahony.
//
// You can find general instructions for this file at www.treeview.net.
//

USETEXTLINKS = 1
STARTALLOPEN = 0
USEFRAMES = 0
USEICONS = 1
WRAPTEXT = 1
PRESERVESTATE = 0


foldersTree = gFld('<b>Image Repository</b><form>%s</form>', "")
  foldersTree.treeID = "Frameless"
%s
}, $inputs, $string;

